package com.sicnu.cheer.leaugebar.leaguemodle.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.sicnu.cheer.leaugebar.leaguemodle.R;
import com.sicnu.cheer.leaugebar.leaguemodle.utils.Utils;

import java.util.List;

import static com.sicnu.cheer.leaugebar.leaguemodle.utils.Utils.setupImage;

public class HorizontalPagerAdapter extends PagerAdapter {

    private List<Utils.LibraryObject> list;

    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public HorizontalPagerAdapter(final Context context, List<Utils.LibraryObject> list) {
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public int getItemPosition(final Object object) {
        return POSITION_NONE;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        final View view;
        view = mLayoutInflater.inflate(R.layout.item_cycleview, container, false);
        setupImage(mContext, (ImageView) view.findViewById(R.id.image), list.get(position));
        container.addView(view);
        return view;
    }

    @Override
    public boolean isViewFromObject(final View view, final Object object) {
        return view.equals(object);
    }

    @Override
    public void destroyItem(final ViewGroup container, final int position, final Object object) {
        container.removeView((View) object);
    }
}
